package com.train.java.oop;

public final class TestEmploy {

	public static void testEncapsulation() {

		Employee emp = new Manager();
		// System.out.println(emp.name); Compile error, because "name" field is private.
		System.out.println(emp.getName());
	}

	public static void testInheritance() {

		/*
		 * "getName" method is defined in Employee class. It can be invoked in
		 * "Manager", "Secretary", "Programmer" class without define it. So it
		 * is recommended to write common logic in super class of many sub
		 * classes. It will be easy to debug, modify related code.
		 */
		Manager manager = new Manager("Man");
		System.out.println(manager.getName());
		Secretary secretary = new Secretary("Sec");
		System.out.println(secretary.getName());
		Programmer programmer = new Programmer("Pro");
		System.out.println(programmer.getName());

		/*
		 * Instance can be assigned to reference of its super class (any level).
		 */
		// Employee employee = new Employee(); Compile error, because abstract class cannot be instantiated.
		// System.out.println(employee.getDescription());
		Employee employee = null;
		employee = manager;
		System.out.println(employee.getName());
		employee = secretary;
		System.out.println(employee.getName());
		employee = programmer;
		System.out.println(employee.getName());
	}

	public static void testInterface() {

		/*
		 * Interface cannot be instantiated. Reference of interface is used to
		 * store a instance whose class implements the interface. It is
		 * recommended to use interface in every level of program. (Define
		 * method in interface and implement it. Use reference of interface to
		 * invoke method.)
		 */
		IFinance finance = new Manager("Manager");
		double money = 1000;
		System.out.println(finance.Pay(money));
	}

	public static void testPolymorphism() {

		/*
		 * Result of invoking method depends on the runtime instance assigned to
		 * the reference. "Employee" class defines "getDescription" method, but
		 * no this result here because every sub-class defines "getDescription"
		 * method, overrides the method in "Employee" class. (That is why the
		 * method is marked by an "override" annotation.
		 */
		Employee employee = null;
		employee = new Manager();
		System.out.println(employee.getDescription());
		employee = new Secretary();
		System.out.println(employee.getDescription());
		employee = new Programmer();
		System.out.println(employee.getDescription());
	}
}
